const TransmissionClient = require('./transmission-client')
const QBitTorrentClient = require('./qbittorrent-client')

const TYPE_TRANSMISSION = 'transmission'
const TYPE_QBITTORRENT = 'qbittorrent'

const CLIENTS = {}

module.exports = {
    getClient(clientConfig, force=false) {
        let client
        if (clientConfig && clientConfig.id){
            client = CLIENTS[clientConfig.id]
            if(!client || force) {
                if (clientConfig.type === TYPE_TRANSMISSION) {
                    client = new TransmissionClient(clientConfig)
                } else if (clientConfig.type === TYPE_QBITTORRENT) {
                    client = new QBitTorrentClient(clientConfig)
                }
                if (client) {
                    CLIENTS[clientConfig.id] = client
                }
            }
        }
        return client
    }
}